var e = require;
var t = module;
var n = exports;
Object.defineProperty(n, "__esModule", {value: !0}), (n.dealCoin = void 0);
var i = e("ExcelgetCoinNum"),
    r = e("ExcelgetCoinNum1"),
    a = e("ExcelgetCoinNum2"),
    s = e("ExcelgetCoinNum3"),
    c = e("ExcelgetCoinNum4"),
    l = e("ExcelgroupType"),
    u = e("ExcelgroupType1"),
    p = e("ExcelgroupType2"),
    h = e("ExcelgroupType3"),
    d = e("ExcelgroupType4"),
    v = e("Excelkeyvalue"),
    b = e("Excellevel1_deal"),
    f = e("index"),
    _ = e("player-coin"),
    w = e("player-info"),
    e =
        ((o.prototype.removeRandOne = function (e) {
            var n = [],
                o = [];
            if (
                (e.forEach(function (e, t) {
                    (e === _.playerCoin.getCoinMaxCount() ? n : o).push(t);
                }),
                0 < o.length)
            ) {
                var t = f.randomInt(0, o.length - 1);
                return o[t];
            }
            t = f.randomInt(0, n.length - 1);
            return o[t];
        }),
        (o.prototype.getCoinNumbers = function (n, e) {
            var o = [];
            if (
                (e.forEach(function (e, t) {
                    o.length < n && o.push(t);
                }),
                o.length < n)
            ) {
                var t = _.playerCoin.getCoinMaxNumber();
                1 === w.playerInfo.getLevel() && t <= 4 && (t = 5);
                for (var i = 6 * (w.playerInfo.getLevel() - 1) + 1; i < t; i++) !e.has(i) && o.length < n && o.push(i);
                if (o.length < n)
                    for (i = 0; i < o.length; i++) {
                        var r = o[i];
                        if (!(o.length < n)) break;
                        o.push(r);
                    }
            }
            return o;
        }),
        (o.prototype.randCoinCount = function (e, t, n) {
            for (var o = f.randomInt(1, t), i = 0, r = 0, a = 0; a < n.length; a++) {
                var s = n[a];
                if ((i += s.useProbility) >= o) {
                    r = s.coinNum;
                    break;
                }
            }
            return Math.min(e, r);
        }),
        (o.prototype.randCoinExcelgroup = function (e, t) {
            for (var n = f.randomInt(1, e), o = 0, i = 0; i < t.length; i++) {
                var r = t[i];
                if ((o += r.useProbility) >= n) return r;
            }
            return t[0];
        }),
        (o.prototype.randNeedNumbers = function (e, t) {
            var n = _.playerCoin.getCoinMaxNumber();
            1 === w.playerInfo.getLevel() && n <= 4 && (n = 5);
            for (var o = 6 * (w.playerInfo.getLevel() - 1) + 1, i = new Array(n - 1 - o), r = 0, a = o; a < n; a++)
                a != e && ((i[r] = a), r++);
            for (var s = [e], a = 0; a < t; a++) {
                var c = f.randomInt(1, i.length),
                    c = i.splice(c - 1, 1);
                s.push(c[0]);
            }
            return s;
        }),
        (o.prototype.getAllProbility = function (e, t) {
            for (var n = 0, o = 0; o < e.length; o++) n += e[o][t];
            return n;
        }),
        (o.prototype.getExcelData = function (e) {
            var n = 0;
            w.playerInfo.getCurTargetNumber(function (e, t) {
                n = t;
            });
            var t = [l.default, u.default, p.default, h.default, d.default],
                o = t[(n = n < 0 || t.length <= n ? 0 : n)].Data,
                t = [i.default, r.default, a.default, s.default, c.default];
            e(o, t[(n = t.length <= n ? 0 : n)].Data);
        }),
        (o.prototype.getDealCoin = function (o, e) {
            var h = this,
                d = w.playerInfo.getLevel(),
                f = new Map(),
                m = null,
                i = null;
            this.getExcelData(function (e, t) {
                (m = e), (i = t);
            });
            var r = this.getAllProbility(i, "useProbility");
            o.forEach(function (e, t) {
                var n = h.randCoinCount(e, r, i);
                n < e && o.set(t, n);
            });
            var y = this.getCoinNumbers(o.size, e);
            y.length !== o.size && console.log("deal error...", y.length, o.size);
            var g = 0,
                v = this.getAllProbility(m, "useProbility");
            return (
                o.forEach(function (e, t) {
                    if (1 === e && y[g])
                        ((l = new _.coinData()).cellIdx = t),
                            (l.num = y[g]),
                            f.has(t) ? ((u = f.get(t)).push(l), f.set(t, u)) : f.set(t, [l]);
                    else if (y[g]) {
                        for (var n = h.randCoinExcelgroup(v, m), o = 0, i = 2; i < e + 1; i++) {
                            var r = Number(n["location" + i]);
                            o < r && (o = r);
                        }
                        for (var a = 1 < d && 4 === e, s = h.randNeedNumbers(y[g], a ? 1 : o - 1), c = 0; c < e; c++) {
                            var l,
                                u,
                                p = Number(n["location" + (c + 1)]) - 1;
                            ((l = new _.coinData()).cellIdx = t),
                                (l.num = s[p]),
                                a && (c < 3 ? ((l.isUnknown = !0), (l.num = s[0])) : (l.num = s[1])),
                                f.has(t) ? ((u = f.get(t)).push(l), f.set(t, u)) : f.set(t, [l]);
                        }
                    }
                    g++;
                }),
                f
            );
        }),
        (o.prototype.getDealCoinByCell = function (e, t) {
            if (t) {
                for (
                    var n = new Map(), o = _.playerCoin.getCoinMaxCount(), i = v.default.GetLine(1).defaultCells, r = 1;
                    r < i + 1;
                    r++
                ) {
                    for (var a = [], s = 0; s < o; s++) {
                        var c,
                            l = b.default.GetLine(s + 1);
                        l["place" + r] &&
                            (((c = new _.coinData()).cellIdx = r - 1), (c.num = Number(l["place" + r])), a.unshift(c));
                    }
                    0 < a.length && n.set(r - 1, a);
                }
                return n;
            }
            var t = w.playerInfo.getUnlockCell(),
                u = Math.min(e.length, t),
                p = new Map(),
                h = _.playerCoin.getCoinMaxNumber();
            1 === w.playerInfo.getLevel() && h <= 4 && (h = 5);
            for (var d = new Map(), f = 0; f < e.length; f++) {
                for (var m = e[f], y = m.getCellData(), r = 0; r < y.length; r++) {
                    var g = y[r].num;
                    g !== h && d.set(g, !0);
                }
                f < u && 0 < (i = m.getCanAddCount()) && p.set(f, i);
            }
            return 1 < p.size && ((t = this.removeRandOne(p)), p.delete(t)), this.getDealCoin(p, d);
        }),
        (o.prototype.getDeal10MaxCoin = function (e) {
            var r = new Map(),
                a = _.playerCoin.getCoinMaxNumber(),
                s = 0;
            return (
                e.forEach(function (e, t) {
                    for (var n, o, i = 0; i < e; i++)
                        s < _.playerCoin.getCoinMaxCount() &&
                            (((n = new _.coinData()).cellIdx = t),
                            (n.num = a),
                            r.has(t) ? ((o = r.get(t)).push(n), r.set(t, o)) : r.set(t, [n]),
                            s++);
                }),
                r
            );
        }),
        o);
function o() {}
n.dealCoin = new e();
